package dacp.etl.kafka.hdfs.process;

import java.util.List;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;

 
public class ProcessSubChain {
	private int inx;
	private ProcessSubChain next;
	private List<Processor> ps = Lists.newArrayList();
	
	public ProcessSubChain(int inx){
		this.inx = inx;
	}
	
	public int getInx(){
		return this.inx;
	}
	
	public void setNext(ProcessSubChain next){
		this.next = next;
	}
	
	public ProcessSubChain next(){
		return this.next;
	}
	
	boolean hasnext(){
		return next != null;
	}
	
	void addProcessor(Processor p){
		ps.add(p);
	}
	
	public String trans(String ori){
		String rst = ori;
		for(Processor pps : ps){
			try{
				rst = pps.process(rst);
			}catch(Exception e){
				//err process
				continue;//ignore
			}
		}
		return rst;
	}
	
	@Override
	public String toString(){
		return  Objects.toStringHelper(this).add("inx", inx).add("processors", ps).add("next", next)
				.toString();
	}
}
